package com.week3.day01;

import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;
import com.sun.org.apache.xerces.internal.xs.StringList;

import java.util.*;

public class MyIterator implements Iterator<String>{
    private Integer count = 0;
    private Integer targetNum = 1;

    public MyIterator() {
    }

    @Override
    public boolean hasNext() {
        if (count.equals(targetNum)) {
            return false;
        }
        return true;
    }

    @Override
    public String next() {
        String strList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        int length = random.nextInt(13) + 4;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(strList.length());
            stringBuilder.append(strList.charAt(index));
        }
        count++;
        return stringBuilder.toString();
    }
    public Collection<String> randomCreat(int num){
        targetNum = num;
        ArrayList<String> strings = new ArrayList<>();
        while (hasNext()){
            strings.add(next());
        }
        return strings;
    }
}
